﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>{$config.sitename}</title>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  <meta name="format-detection" content="telephone=no" />
  <link rel="stylesheet" href="../../../css/font-awesome/css/font-awesome.min.css" />
  <link href="../../../shop/templates/cdrt/css/comment.css" rel="stylesheet" />
  <style>
    .header {
      position: inherit;
    }
  </style>
  <!--<script>
    var selectedscore = 0;
    window.onload = function () {
      var word = ['差评', '中评', '中评', "好评", "好评"];

      $('[name=pf]').click(function () {
        var li = $(this);
        var score = $(this).attr('index');
        selectedscore = score;
        $('[name=pf]').removeClass('act');
        $('[name=pf]').filter(':lt(' + score + ')').addClass('act');
        $('#star_word').text(word[score - 1]);
        $('#hidscore').val(score);
      })

      $('[name=pf]').mouseover(function () {
        var li = $(this);
        var score = $(this).attr('index');
        $('[name=pf]').removeClass('act');
        $('[name=pf]').filter(':lt(' + score + ')').addClass('act');
        $('#star_word').text(word[score - 1]);
      })

      $('[name=pf]').mouseout(function () {
        $('[name=pf]').removeClass('act');
        $('[name=pf]').filter(':lt(' + selectedscore + ')').addClass('act');
        $('#star_word').text(word[selectedscore - 1]);
      })
    }

    function getQueryString(name) {
      var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
      if (result == null || result.length < 1) {
        return "";
      }
      return result[1];
    }

    function submit() {
      var data = {

      }
      data.wid = getQueryString("wid");
      data.pid = getQueryString("pid");
      data.skuid = getQueryString("skuid");
      data.openid = getQueryString("openid");
      data.orderid = getQueryString("orderid");
      data.content = $('#txtcontent').val();
      data.score = $('#hidscore').val();
      if (data.pid == 0 || data.orderid == '') {
        alert('请退回订单页面重新进入评价页！');
        return;
      }

      if (data.score == 0) {
        alert('请先进行评分');
        return;
      }

      $.ajax({
        url: '/shop/shopmgr.ashx?myact=product_evaluate', //'ajax.ashx?action=getTotal',
        type: 'get',
        dataType: 'json',
        data: data,
        success: function (res) {
          alert(res.msg);
        }
      });
    }
  </script>-->
</head>

<body>
  <div class="page" id="page">
    <header class="header">
      <a class="back" href="javascript:history.go(-1);">
        <i class="fa fa-chevron-left"></i>
      </a>
      评价
      <span class="submit" v-on:click="submit">
        提交评价
      </span>
    </header>
    <section class="content">
      <div class="raty-wapper">
        <span class="text">总体评价</span>
        <span class="raty"></span>
        <span class="score">{{comment.score}}分</span>
      </div>
      <div class="message">
        <textarea id="txtcontent" placeholder="说两句吧" maxlength="500" v-model="comment.content"></textarea>
      </div>
    </section>
  </div>
  <input type="file" style="display: none" id="imgfileupload" name="Filedata" accept="image/*" size="8" />
  <!--<div class="wrapper">
    <span id="result">评价内容</span>
    <textarea id="txtcontent" rows="5" style="width:95%"></textarea>
    <table>
      <tr>
        <td width="10%">
          <span id="result">评分</span>
        </td>
        <td width="65%">
          <ul id="star">
            <li index="1" name="pf">★</li>
            <li index="2" name="pf">★</li>
            <li index="3" name="pf">★</li>
            <li index="4" name="pf">★</li>
            <li index="5" name="pf">★</li>
          </ul>
        </td>
        <td width="25%">
          <span id="star_word">评级</span>
        </td>
      </tr>
    </table>
    <input type="hidden" id="hidscore" value="">
    <input type="button" id="btnsubmit" value="提交" onclick="submit();" class="btn-info btn-large">
  </div>

  <header class="header">
    <a class="back" href="javascript:history.go(-1);">
      <i class="fa fa-chevron-left"></i>
    </a>
    评价列表
  </header>
  <div class="content">
    <section class="shop-info" id="info"></section>
    <ul class="comment-list" id="list"></ul>
    <div class="more">
      <a id="loadMore" onclick="getList();">查看更多</a>
    </div>
  </div>
  </div>-->

  <input name='wid' type=hidden value="{$wid}">
  <input name='openid' type=hidden value="{$openid}">
  <input name='productid' type=hidden value="{$productid}" >
  <input name='skuid' type=hidden value="{$skuid}">

  <script src="../../../shop/templates/cdrt/js/jquery-2.0.2.min.js"></script>
  <script src="../../../shop/templates/cdrt/js/vue/vue.min.js"></script>
  <script src="../../../shop/templates/cdrt/js/layer/layer.js"></script>
  <script src="./../../shop/templates/cdrt/js/jquery.ui.widget.js"></script>
  <!--<script src="../../../shop/templates/cdrt/js/handlebars.js"></script>-->
  <script src="../../../shop/templates/cdrt/js/raty/jquery.raty.min.js"></script>
  <script src="../../../shop/templates/cdrt/js/jquery.fileupload.min.js"></script>
  <script>
    $.fn.raty.defaults.path = '../../../shop/templates/cdrt/images/';
    var ui = {
      showLoading: function(message) {
        message = message || '加载中...';
        layer.open({
          content: message
        });
      },
      alert: function(message) {
        layer.open({
          content: message,
          btn: ['确定']
        });
      },
      getQuerySting: function(name) {
        var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
        if (result == null || result.length < 1) {
          return "";
        }
        return result[1];
      }
    }

    var infoViewModel = new Vue({
      el: '#page',
      data: {
        comment: {
          score: 0,
          content: '',
          images: []
        }
      },
      methods: {
        initParams: function() {
          this.comment.orderId = ui.getQuerySting('orderid');
          this.comment.productId = ui.getQuerySting('pid');
          this.comment.businessId = ui.getQuerySting('bid');
          this.comment.businessType = ui.getQuerySting('type');
          this.comment.openId = ui.getQuerySting('openid');
          console.log(this.comment.openId);
          this.comment.skuId = ui.getQuerySting('skuid') == "" ? 0 :ui.getQuerySting('skuid');
          this.comment.businessId = ui.getQuerySting('wid');
          this.comment.businessType = 0;
          this.comment.wid = ui.getQuerySting('wid');
        },
        initRaty: function() {
          var self = this;
          $('.raty').raty({
            width: 180,
            click: function(score) {
              self.comment.score = score;
            }
          });
        },
        choose: function() {
          $('#imgfileupload').click();
        },
        submit: function() {
          var self = this;
          if (!this.comment.content.length) {
            ui.alert('说两句，给点意见吧~~');
            return;
          }
          ui.showLoading("正在提交中...");
          var data = {

          }
          data.wid = ui.getQuerySting("wid");
          data.productid = ui.getQuerySting("pid");
          data.skuid = ui.getQuerySting("skuid");
          data.openid = ui.getQuerySting("openid");
          data.orderid = ui.getQuerySting("orderid");
          data.content = $('#txtcontent').val();
          data.score = $('#hidscore').val();

          //console.log(self.comment);
          //console.log(JSON.stringify(self.comment));

          $.ajax({
            url: '/shop/shopmgr.ashx?myact=product_evaluate', //'ajax.ashx?action=getTotal',
            type: 'post',
            dataType: 'json',
            data: JSON.stringify(self.comment),
            success: function (res) {
              console.log(res);
              layer.closeAll();
              if (res.isSuccess) {
                if (document.referrer) {
                  location.href = document.referrer;
                }
              } else {
                console.log("res:" + res);
                console.log("res.data:" + res.data);
                ui.alert(res.Message);
              }
            },
            error: function (err, res) {
              
              ui.alert(res.data.message);
            }
          });
          /*
          $.ajax({
            url: 'ajax.ashx?action=add',
            type: 'post',
            dataType: 'json',
            data: {
              data: JSON.stringify(self.comment)
            },
            success: function(res) {
              layer.closeAll();
              if (res.isSuccess) {
                if (document.referrer) {
                  location.href = document.referrer;
                }
              }
            }
          });
          */
        },
        initUploader: function() {
          var self = this;
          var uploader = $("#imgfileupload");
          uploader.fileupload({
            url: '../../tools/upload_ajax.ashx?IsThumbnail=1',
            acceptFileTypes: /(\.|\/)(rar|zip|jp?g|png|bmp)$/i,
            sequentialUploads: true,
            singleFileUploads: true,
            maxChunkSize: 10000000,
            limitMultiFileUploads: 8,
            dataType: 'json',
            success: function(result, date) {
              layer.closeAll();
              if (result.status) {
                self.comment.images.push({
                  path: result.path,
                  thumbPath: result.thumb
                });
              }
            },
            change: function(e, data) {
              ui.showLoading('正在上传...');
            },
            error: function(e, data) {
              layer.closeAll();
              ui.alert('图片上传失败');
            }
          });
        }
      },
      ready: function() {
        this.initParams();
        this.initRaty();
        this.initUploader();
      }
    });
  </script>
</body>

</html>